package com.wx.spring.ioc.factory;

import com.wx.spring.exception.SpringIocException;
import com.wx.spring.ioc.IocContainer;
import com.wx.spring.utils.ConvertUtis;
import com.wx.spring.utils.MyStringUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * @author wx
 * @Description: Spring 上下文
 * @date 2019/1/9 000920:34
 */
@Slf4j
public class ApplicationContext implements BeanFactory {


    @Override
    public Object getBean(String beanId) throws SpringIocException {
        if (MyStringUtils.isBlank(beanId)) {
            throw new NullPointerException("beanId为空");
        }
        Object object = IocContainer.getBeanMap().get(beanId);
        if (object != null) {
            return object;
        }
        return object;
    }

    @Override
    public Object getBean(Class c) throws SpringIocException {
        return getBean(ConvertUtis.toLowerCaseFirstOne(c.getSimpleName()));
    }


}
